﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="paring3_paring", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Paring3Paring))]
    public class Paring3ParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IParing3Paring clazz;
        
        public Paring3ParingSerializer(IParing3Paring clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("regmrk");
            if (clazz.Regmrk!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Regmrk))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("idkood");
            if (clazz.Idkood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Idkood))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("oma_andmed");
            if (clazz.OmaAndmed!=null) {
                global::Xtee.Core.SerializationMetadata metaOmaAndmed = this.GetMetaData(clazz.OmaAndmed);
                Writer.WriteTypeAttribute(metaOmaAndmed.TypeQualifiedName.Namespace, metaOmaAndmed.TypeQualifiedName.Name);
                metaOmaAndmed.NewSerializer(clazz.OmaAndmed).WriteXml(Writer);
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kasutajad");
            if (clazz.Kasutajad!=null) {
                global::Xtee.Core.SerializationMetadata metaKasutajad = this.GetMetaData(clazz.Kasutajad);
                Writer.WriteTypeAttribute(metaKasutajad.TypeQualifiedName.Namespace, metaKasutajad.TypeQualifiedName.Name);
                metaKasutajad.NewSerializer(clazz.Kasutajad).WriteXml(Writer);
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("regtun");
            if (clazz.Regtun!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Regtun))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("vinkood");
            if (clazz.Vinkood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Vinkood))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "regmrk")) {
                goto regmrk;
            }
            else {
                if ((Reader.LocalName == "idkood")) {
                    goto idkood;
                }
                else {
                    if ((Reader.LocalName == "oma_andmed")) {
                        goto oma_andmed;
                    }
                    else {
                        if ((Reader.LocalName == "kasutajad")) {
                            goto kasutajad;
                        }
                        else {
                            if ((Reader.LocalName == "regtun")) {
                                goto regtun;
                            }
                            else {
                                if ((Reader.LocalName == "vinkood")) {
                                    goto vinkood;
                                }
                                else {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        regmrk:
            if ((Reader.IsElementNil() == false)) {
                clazz.Regmrk = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("regmrk")).Value;
            }
            else {
                Reader.Skip();
            }
            goto START;
        idkood:
            if ((Reader.IsElementNil() == false)) {
                clazz.Idkood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("idkood")).Value;
            }
            else {
                Reader.Skip();
            }
            goto START;
        oma_andmed:
            if ((Reader.IsElementNil() == false)) {
                global::Xtee.Core.SerializationMetadata metaOmaAndmed = this.GetMetaData<Paring3Paring.IOmaAndmedType>(Reader, ">>paring3_paring>oma_andmed", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                clazz.OmaAndmed = metaOmaAndmed.NewEntity<Paring3Paring.IOmaAndmedType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("oma_andmed");
                    metaOmaAndmed.NewSerializer(clazz.OmaAndmed).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                Reader.Skip();
            }
            goto START;
        kasutajad:
            if ((Reader.IsElementNil() == false)) {
                global::Xtee.Core.SerializationMetadata metaKasutajad = this.GetMetaData<Paring3Paring.IKasutajadType>(Reader, ">>paring3_paring>kasutajad", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                clazz.Kasutajad = metaKasutajad.NewEntity<Paring3Paring.IKasutajadType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kasutajad");
                    metaKasutajad.NewSerializer(clazz.Kasutajad).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                Reader.Skip();
            }
            goto START;
        regtun:
            if ((Reader.IsElementNil() == false)) {
                clazz.Regtun = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("regtun")).Value;
            }
            else {
                Reader.Skip();
            }
            goto START;
        vinkood:
            if ((Reader.IsElementNil() == false)) {
                clazz.Vinkood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("vinkood")).Value;
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>paring3_paring>oma_andmed", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Paring3Paring.OmaAndmedType))]
        public class OmaAndmedTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected Paring3Paring.IOmaAndmedType clazz;
            
            public OmaAndmedTypeSerializer(Paring3Paring.IOmaAndmedType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("oma_kood");
                if (clazz.OmaKood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OmaKood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OmaKood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("oma_nimi");
                if (clazz.OmaNimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OmaNimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OmaNimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("oma_eesnimi");
                if (clazz.OmaEesnimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OmaEesnimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OmaEesnimi");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
            START:
                if ((Reader.LocalName == "oma_kood")) {
                    goto oma_kood;
                }
                else {
                    if ((Reader.LocalName == "oma_nimi")) {
                        goto oma_nimi;
                    }
                    else {
                        if ((Reader.LocalName == "oma_eesnimi")) {
                            goto oma_eesnimi;
                        }
                        else {
                            return;
                        }
                    }
                }
            oma_kood:
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>paring3_paring>oma_andmed>oma_kood");
                }
                clazz.OmaKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oma_kood")).Value;
                goto START;
            oma_nimi:
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>paring3_paring>oma_andmed>oma_nimi");
                }
                clazz.OmaNimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oma_nimi")).Value;
                goto START;
            oma_eesnimi:
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>paring3_paring>oma_andmed>oma_eesnimi");
                }
                clazz.OmaEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oma_eesnimi")).Value;
                goto START;
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>paring3_paring>kasutajad", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Paring3Paring.KasutajadType))]
        public class KasutajadTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected Paring3Paring.IKasutajadType clazz;
            
            public KasutajadTypeSerializer(Paring3Paring.IKasutajadType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                for (int x = 0; ((clazz.Item != null) 
                            && (x < clazz.Item.Count)); x = (x + 1)) {
                    if (clazz.Item[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaItem = this.GetMetaData(clazz.Item[x]);
                        Writer.WriteTypeAttribute(metaItem.TypeQualifiedName.Namespace, metaItem.TypeQualifiedName.Name);
                        metaItem.NewSerializer(clazz.Item[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="item") {
                    clazz.Item = new System.Collections.Generic.List<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IKasutaja>();
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>paring3_paring>kasutajad>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaItem = this.GetMetaData<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IKasutaja>(Reader, "kasutaja", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                        global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IKasutaja item = metaItem.NewEntity<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IKasutaja>();
                        clazz.Item.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaItem.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                }
            }
        }
    }
}
